<!--
 * @Description: 车载设备维护
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: yjx
 * @LastEditTime: 2021-12-29 14:16:10
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display: flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </div>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px">设备名称</span>
                  <el-input v-model="tableParam.name" style="width: 240px" clearable />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">车牌号</span>
                  <el-input v-model="tableParam.code" style="width: 240px" clearable />
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <!-- <div class="card scroll"> -->
          <div class="card">
            <div class="card_nav">
              <div>
                <el-button size="small" class="bottom_all" style="margin-left: 0" @click="addFromDate('添加')">
                  <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                  添加
                </el-button>
                <!-- <el-button size="small" class="bottom_two" @click="UpdateOrDelete('update_status', 0)">
                  <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                  删除
                </el-button> -->
                <el-button size="small" class="bottom_three" @click="UpdateOrDelete('update_enable', 1)">
                  <i class="icon iconfont iconicon_button_startuse" style="font-size: 12px"></i>
                  启用
                </el-button>
                <el-button size="small" class="bottom_four" @click="UpdateOrDelete('update_enable', 0)">
                  <i class="icon iconfont iconicon_button_disable1" style="font-size: 12px"></i>
                  禁用
                </el-button>
              </div>
              <div>
                <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='BAOCUNPXH'))!==-1" :underline="false" @click="SortNum()">
                  <span class="el-icon--left">
                    <i class="iconfont iconicon_button_sort1"></i>
                  </span>
                  保存排序号
                </el-link>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
                <el-table-column align="center" type="selection"></el-table-column>
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'?'right':false">
                    <template slot-scope="scope">
                      <span v-if="item.label == '状态'">
                        <span v-if="scope.row.enable == 0" style="color: #969799">禁用</span>
                        <span v-if="scope.row.enable == 1" style="color: #00a754">启用</span>
                      </span>
                      <div v-else-if="item.label == '操作'">
                        <el-dropdown :hide-on-click="false" trigger="click">
                          <el-button size="mini" class="bottom_one">更多</el-button>
                          <el-dropdown-menu slot="dropdown" style="text-align: left">
                            <el-dropdown-item>
                              <el-button style="margin:5px 0" class="bottom_one" size="mini" @click="pageupdateFromDate(scope.row, '修改')">
                                修改
                              </el-button>
                            </el-dropdown-item>
                            <el-dropdown-item>
                              <el-button style="margin:5px 0" class="bottom_one" size="mini" @click="seeDialog(scope.row)">
                                查看
                              </el-button>
                            </el-dropdown-item>
                            <el-dropdown-item>
                              <el-button style="margin:5px 0" class="bottom_one" size="mini" @click="trajectoryDialog(scope.row)">
                                车载轨迹
                              </el-button>
                            </el-dropdown-item>
                          </el-dropdown-menu>
                        </el-dropdown>
                      </div>
                      <div v-else-if="item.label == '排序号'">
                        <el-input v-model="scope.row.sortNum"></el-input>
                      </div>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 增加修改 -->
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="480px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="fromDate" label-width="110px">
          <el-form-item prop="companyId">
            <span slot="label" style="color: #ff0000">所属单位</span>
            <el-select ref="company" v-model="fromDate.companyId" placeholder="请选择" @change="getCarNo(),$nextTick(()=>{fromDate.companyName = $refs.company.selectedLabel})">
              <el-option v-for="(item, index) in companyList" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="name">
            <span slot="label" style="color: #ff0000">设备名称</span>
            <el-input v-model="fromDate.name" style="width:240px;" placeholder="请输入" clearable>
            </el-input>
          </el-form-item>
          <el-form-item prop="carNo" label="车牌号">
            <el-select v-model="fromDate.carNo" placeholder="请选择" :disabled="!fromDate.companyId">
              <el-option v-for="(item, index) in carNoList" :key="index" :label="item.plateNumber" :value="item.plateNumber"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="physicalAddress" label="物理地址">
            <el-input v-model="fromDate.physicalAddress" style="width:240px;" placeholder="请输入" clearable>
            </el-input>
          </el-form-item>
          <el-form-item prop="typeId" label="设备类型">
            <el-select ref="typeId" v-model="fromDate.typeId" placeholder="请选择" @change="$nextTick(()=>{fromDate.typeName = $refs.typeId.selectedLabel})">
              <el-option v-for="(item, index) in typeList" :key="index" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="状态" prop="enable">
            <el-radio-group v-model="fromDate.enable">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="0">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submitFromDate()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看 -->
    <el-dialog v-dialogDrag :visible.sync="seeStatus" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">查看</span>
      <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark">
        <el-table-column label="设备名称"></el-table-column>
        <el-table-column label="产品名"></el-table-column>
        <el-table-column label="司机名称"></el-table-column>
        <el-table-column label="地理位置"></el-table-column>
        <el-table-column label="经纬度坐标"></el-table-column>
        <el-table-column label="网速"></el-table-column>
        <el-table-column label="回传时间"></el-table-column>
      </el-table>
      <div class="pagination">
        <div class="top_page_totle">总共{{ seeTotal }}条</div>
        <el-pagination :current-page.sync="seeFrom.page" :page-size="seeFrom.pageSize" layout="prev, pager, next, jumper" :total="seeTotal"></el-pagination>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="seeStatus=false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 车载轨迹 -->
    <el-dialog v-dialogDrag :visible.sync="trajectoryStatus" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">车载轨迹</span>
      <div>
        <span style="margin-left: 24px">
          <span style="margin-right: 12px">时间段</span>
          <el-date-picker v-model="trajectoryTime" type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </span>
      </div>
      <el-amap :zoom="zoom" :center="mapCenter" class="amap-demo">
      </el-amap>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="trajectoryStatus=false">取 消</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import { getDicType, permissionsCompanyList } from "@/api/common.js";
import {
  queryPage,
  batchUpdateOrDelete,
  updateSortNum,
  saveOrUpdate,
  QueryListByCompanyId
} from "@/api/basicConfig/carEquipmentManagement.js";
export default {
  mixins: [mixin],
  data() {
    return {
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      batchUpdateOrDelete: batchUpdateOrDelete,
      updateSortNum: updateSortNum,
      saveOrUpdate: saveOrUpdate,
      /*表格数据*/
      table: [
        { label: "设备编号", width: "auto", prop: "id", status: true },
        { label: "所属单位", width: "120", prop: "companyName", status: true },
        { label: "设备名称", width: "auto", prop: "name", status: true },
        { label: "车牌号", width: "120", prop: "carNo", status: true },
        { label: "物理地址", width: "auto", prop: "physicalAddress", status: true },
        { label: "设备类型", width: "120", prop: "typeName", status: true },
        { label: '排序号', width: '120', prop: 'sortNum', status: true },
        { label: "状态", width: "auto", prop: "", status: true },
        { label: "操作", width: "100", prop: "", status: true },
      ],
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        companyId: [{ required: true, message: "请选择所属单位", trigger: "change" }],
        name: [{ required: true, message: "请输入设备名称", trigger: "blur" }]
      },
      fromDate: {
        id: "",
        companyId: "",
        companyName: "",
        name: "",
        carNo: "",
        physicalAddress: "",
        typeId: "",
        typeName: "",
        enable: 1
      },
      typeList: [],
      companyList: [],
      carNoList: [],
      /**查看*/
      seeStatus: false,
      row: {},
      seeFrom: {
        page: 1,
        pageSize: 10,

      },
      seeTotal: 0,
      /**车载轨迹*/
      trajectoryStatus: false,
      trajectoryTime: '',
      zoom: 14,
      mapCenter: [104.053317, 30.549161],

    };
  },
  created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, name: "", code: "" };
    this.tableData = [{}]
    getDicType({ code: 'TypeofonBoardEquipment' }).then(res => {
      this.typeList = res.data.items
    })
    permissionsCompanyList().then(res => {
      this.companyList = res
    })
    this.gettableData();
  },
  methods: {
    getCarNo() {
      QueryListByCompanyId({ companyId: this.fromDate.companyId }).then(res => {
        this.carNoList = res.data
        this.fromDate.carNo = ''
      })
    },
    /*重置数据,此方法必须存在，并且方发只重置条件*/
    seeDialog(row) {
      this.row = row
      this.seeStatus = true
    },
    trajectoryDialog(row) {
      this.row = row
      this.trajectoryStatus = true
    },
    init() {
      this.tableParam.name = "";
      this.tableParam.code = "";
      this.gettableData();
    },
    async pageupdateFromDate(row, text) {
      await QueryListByCompanyId({ companyId: row.companyId }).then(res => {
        this.carNoList = res.data
      })
      this.updateFromDate(row, text)
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    }
  },
};
</script>

<style lang="scss" scoped>
.el-select {
  width: 240px;
}
.amap-demo {
  margin-top: 20px;
  height: 570px;
}
</style>
